﻿using System.Collections.Generic;

namespace Soul.Excel
{
    public class ExcelDataTable
    {
        public string Title { get; set; }
        public string Name { get; set; }
        public float? TitleRowHeight { get; set; }
        public float? ColumnRowHeight { get; set; }
        public int TitleFontHeight { get; set; } = 16;
        public int HeaderFontHeight { get; set; } = 10;
        public int FooterFontHeight { get; set; } = 10;
        public int ColumnFontHeight { get; set; } = 10;
        public int DataFontHeight { get; set; } = 10;

        internal ExcelBlankRow ExcelBlankRowAfterDataRow { get; set; }

        public ExcelHeaderCollection Headers { get; } = new ExcelHeaderCollection();

        public ExcelHeaderCollection Footers { get; } = new ExcelHeaderCollection();

        public ExcelDataColumnCollection Columns { get; } = new ExcelDataColumnCollection();

        public ExcelDataRowCollection Rows { get; } = new ExcelDataRowCollection();

        public ExcelMergeRegionCollection MergeRegions { get; } = new ExcelMergeRegionCollection();

        public List<ExcelGroup> GroupRows { get; } = new List<ExcelGroup>();

        public bool IsClearMergedCells { get; set; } = true;

        public ExcelDataTable()
        {

        }

        public ExcelDataTable(string name) : this(name, name)
        {

        }

        public ExcelDataTable(string name, string title)
        {
            Name = name;
            Title = title;
        }

        public ExcelDataRow NewRow()
        {
            return new ExcelDataRow(this);
        }

        public void AddExcelBlankRowAfterDataRow(int rowCount)
        {
            ExcelBlankRowAfterDataRow = new ExcelBlankRow(rowCount);
        }

        public void GroupRow(int fromRow,int toRow)
        {
            GroupRows.Add(new ExcelGroup 
            {
                FromRow = fromRow,
                ToRow = toRow
            });
        }

        public ExcelDataTable Clone(string name, string title)
        {
            var table = new ExcelDataTable(name, title);
            foreach (var item in Headers)
            {
                table.Headers.Add(item);
            }
            foreach (var item in Footers)
            {
                table.Footers.Add(item);
            }
            foreach (var item in Columns)
            {
                table.Columns.Add(item);
            }
            return table;
        }

        public ExcelDataTable Clone(string name)
        {
            return Clone(name, name);
        }

        internal int? FreezeRowIndex;

        internal int? FreezeColIndex;

        public void Freeze(int rowIndex, int colIndex)
        {
            FreezeRowIndex = rowIndex;
            FreezeColIndex = colIndex;
        }
    }
}
